package com.yidu.best.basicSetup.custodian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yidu.best.basicSetup.custodian.dao.CustodianDao;
import com.yidu.best.basicSetup.custodian.domain.Custodian;
import com.yidu.best.basicSetup.custodian.domain.CustodianVo;
import com.yidu.best.basicSetup.custodian.service.CustodianService;
@Service
public class CustodianServiceImpl implements CustodianService{

	@Autowired
	private CustodianDao custodianDao;
	
	
	public CustodianServiceImpl() {
		super();
	}
	

	public CustodianServiceImpl(CustodianDao custodianDao) {
		super();
		this.custodianDao = custodianDao;
	}
	

	public CustodianDao getCustodianDao() {
		return custodianDao;
	}


	public void setCustodianDao(CustodianDao custodianDao) {
		this.custodianDao = custodianDao;
	}


	@Override
	public Map<String, Object> queryCustodianMapByCriteriaWithPage(CustodianVo custodianVo) {
		
		int page = (custodianVo.getPage()-1)*custodianVo.getLimit(); custodianVo.setPage(page);
		List<Custodian> pageByParam = custodianDao.selectPageParam(custodianVo);
		System.out.println(pageByParam);
		int count = custodianDao.selectCount(custodianVo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("data",pageByParam);
		map.put("count", count);
		map.put("msg", "");
		map.put("code", 0);
		return map;
	}

	

	

	@Override
	public int selectCount(Custodian custodian) {
		// TODO Auto-generated method stub
		return 0;
	}


	@Override
	public int addCustodian(Custodian custodian) {
		// TODO Auto-generated method stub
		return custodianDao.addCustodian(custodian);
	}


	@Override
	public int updateCustodian(Custodian custodianId) {
		// TODO Auto-generated method stub
		return custodianDao.updateCustodian(custodianId);
	}


	@Override
	public int deleteCustodian(String custodianIdStr) {
		Map<String, Object> map =  new HashMap<String, Object>();
		String[] custodianId = custodianIdStr.split(",");
		int total = 0;
		for (int i = 0; i < custodianId.length; i++) {
			map.put("custodianId", custodianId[i]);
			int result = custodianDao.deleteById(map);
			total+=result;
		}
		return total;
	}

	/**
	 * 逻辑删除
	 */
	@Override
	public int logicDelete(Custodian custodian) {
		// TODO Auto-generated method stub
		return custodianDao.logicDelete(custodian);
	}

	/**
	 * 基金表查询管理人Id的方法
	 */
	@Override
	public List<Custodian> findByAllCustodian() {
		
		return custodianDao.findByAllCustodian();
	}
	
}
